<template>
    <view class="u-demo-block__content" v-if="data.user">
        <view class="album">
            <view class="album__avatar">
                <image :src="joinDomain(data.user.avatar)" style="width: 70rpx;height: 70rpx;"></image>
            </view>
            <view class="album__content">
                <u--text :text="data.user.nickname" type="primary" bold size="17"></u--text>
                <u--text margin="0 0 8px 0" :text="data.content"></u--text>
                <u-album :urls="urls(data.pictures)" keyName="url"></u-album>
                <view class="date">
                    <text>{{data.createTime}}</text>
                    <text v-if="data.user.username === user.username" class="del" @click="show = true">删除</text>
                    <text class="state" v-if="data.state === pending">{{stateName(data.state)}}</text>
                </view>
            </view>
        </view>
        <u-modal :show="show" title="提示" showCancelButton @confirm="confirm" @cancel="show = false">
            <view class="slot-content">
                <rich-text nodes="删除该动态？"></rich-text>
            </view>
        </u-modal>
    </view>
</template>

<script>
    export default {
        props: {
            data: Object
        },
        data() {
            return {
                show: false,
                content: ''
            }
        },
        computed: {
            user() {
                return this.$store.state.user
            },
            pending() {
              return this.$store.state.newsState.pending
            },
            stateName() {
              return (state) => {
                return this.$store.state.newsState[state]
              }
            },
            urls() {
              return (list) => {
                return list.map(item => {
                  return {
                    ...item,
                    url: this.joinDomain(item.url)
                  }
                })
              }
            }
        },
        methods: {
            confirm() {
                this.$emit('delete', this.data._id)
            }
        }
    }
</script>

<style lang="scss" scoped>
    .album {
        @include flex;
        align-items: flex-start;
        
        &__avatar {
            // background-color: $u-bg-color;
            // padding: 5px;
            border-radius: 50%;
            overflow: hidden;
        }
    
        &__content {
            margin-left: 20rpx;
            flex: 1;
        }
    }
    .date{
        margin-top: 20rpx;
        color: $uni-text-color-grey;
        font-size: $me-text-min-size;
    }
    .del{
        color: #3C9CFF;
        margin-left: 20rpx;
    }
    .state{
      margin-left: 10rpx;
    }
</style>